<?php
namespace App\Repositories;


use App\Exceptions\BasicException;

class RiskRepository
{
    /**
     * 新增
     * @param $param
     * @return bool
     * @throws BasicException
     */
    public function addRechargeLimit($param) {
        $addConfig = app('model_recharge_limit')->create($param);

        if ($addConfig) return $addConfig;
        throw new BasicException(93045);
    }

    /**
     * 删除
     */
    public function delRechargeLimit($idArr = []) {
        $res = app('model_recharge_limit')->whereIn("id", $idArr)->delete();

        if ($res) return $res;
        throw new BasicException(93044);
    }

    /**
     * 修改
     */
    public function saveRechargeLimit($where,$param) {
        $saveConfig = app('model_recharge_limit')->where($where)->update($param);

        if ($saveConfig!==false) return true;
        throw new BasicException(93047);
    }

    /**
     * 单条
     */
    public function getRechargeLimit($where) {
        $result = app('model_recharge_limit')->where($where)->first();

        return $result;
    }

    /**
     * 管理员后台查询配置数据
     */
    public function getRechargeLimitQueryList(Array $params) {
        $whereArr = [];

        $whereFunc = function ($query) use ($params) {
        };

        $page = empty($params['page']) ? 1 : $params['page'];
        $perPage = empty($params['perPage']) ? 10 : $params['perPage'];

        $result = app('model_recharge_limit')->where($whereArr)->where($whereFunc)->orderBy('id','desc')->paginate($perPage, ['*'], '', $page);

        return $result;
    }
}